import 'dart:convert';

import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart';

class CryptoUtils {

  /// md5 加密
  static String toMD5(String data) {
    var content = const Utf8Encoder().convert(data);
    var digest = md5.convert(content);
    return hex.encode(digest.bytes);
  }

  /// Base64加密
  static String encodeBase64(String data) {
    var content = utf8.encode(data);
    var digest = base64Encode(content);
    return digest;
  }

  /// Base64解密
  static String decodeBase64(String data) {
    return String.fromCharCodes(base64.decode(data));
  }

  static String toSha1(String data) {
    var content = const Utf8Encoder().convert(data);
    var digest = sha1.convert(content);
    return digest.toString().toUpperCase();
  }
}